/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package client.gui.smilies;

import java.util.Hashtable;
import org.apache.log4j.Logger;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/**
 *
 * @author 
 */
public class CSAXDefaultHandlerSmileys extends CSAXHandlerSmileys {
    //attributen
    private String naamLaatsteElement;
    private Hashtable<String, IXmlSmileyFunction> functionStartElement = new Hashtable<String, IXmlSmileyFunction>();
    private Hashtable<String, IXmlSmileyFunction> functionEndElement = new Hashtable<String, IXmlSmileyFunction>();
    private Hashtable<String, IXmlSmileySetFunction> functionCharacter = new Hashtable<String, IXmlSmileySetFunction>();

    public CSAXDefaultHandlerSmileys() {
        super();
        naamLaatsteElement = null;

        functionStartElement.put("chat", new StartEmoticonLijst());
        functionStartElement.put("emoticon", new StartEmoticon());

        functionEndElement.put("chat", new EndEmoticonLijst());
        functionEndElement.put("emoticon", new EndEmoticon());

        functionCharacter.put("text", new SetText());
        functionCharacter.put("location", new SetLocation());
    }

    public DefaultHandler getDefaultHandler() {
        return new DefaultHandler() {

            public void startElement(String namespaceURI, String localName,
                    String qualifiedName, Attributes atts) throws SAXException {
                naamLaatsteElement = qualifiedName;
                try{
                    functionStartElement.get(qualifiedName).execute();
                }catch(Exception ex){}

            }

            public void endElement(String namespaceURI, String localName,
                    String qualifiedName) throws SAXException {
                try{
                    functionEndElement.get(qualifiedName).execute();
                }catch(Exception ex){}
            }

            public void characters(char[] text, int start, int length)
                    throws SAXException {
                try{
                    functionCharacter.get(naamLaatsteElement).execute(new String(text,start,length));
                }catch(Exception ex){}
            }
        };
    }

    class StartEmoticonLijst implements IXmlSmileyFunction {

        public void execute() {
            startEmoticonLijst();
        }
    }

    class StartEmoticon implements IXmlSmileyFunction {

        public void execute() {
            startEmoticon();
        }
    }

    class EndEmoticonLijst implements IXmlSmileyFunction {

        public void execute() {
            endEmoticonLijst();
        }
    }

    class EndEmoticon implements IXmlSmileyFunction {

        public void execute() {
            endEmoticon();
        }
    }

    class SetText implements IXmlSmileySetFunction {

        public void execute(String s) {
            setText(s);
        }
    }

    class SetLocation implements IXmlSmileySetFunction {

        public void execute(String s) {
            setLocation(s);
        }
    }
}






